package com.atguigu.educms.controller;


import com.atguigu.commonutils.Result;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 后台banner的管理接口表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2024-07-02
 */
@Api("测试Banner模块")
@RestController
@RequestMapping("/educms/bannerAdmin")
@CrossOrigin//解决跨域问题
@Slf4j
public class BannerAdminController {

    @Autowired
    private CrmBannerService crmBannerService;
    //分页查询banner
    @GetMapping("pageBanner/{page}/{limit}")
    public Result pageBanner(@PathVariable long page,
                             @PathVariable long limit) {
        Page<CrmBanner> crmBannerPage = new Page<>(page, limit);
        crmBannerService.page(crmBannerPage, null);
        log.info("这是多少？：" +crmBannerPage.getTotal());
        return Result.ok().data("items",crmBannerPage.getRecords()).data("total",crmBannerPage.getTotal());
    }
    //添加banner
    @PostMapping("addBanner")
    public Result addBanner(@RequestBody CrmBanner crmBanner) {
            crmBannerService.save(crmBanner);
            return Result.ok();
    }
    //修改banner
    @PutMapping("updateBanner")
    public Result updateBanner(@RequestBody CrmBanner crmBanner) {
        crmBannerService.updateById(crmBanner);
        return Result.ok();
    }
    //删除banner
    @DeleteMapping("deleteBanner")
    public Result deleteBanner(String id) {
        crmBannerService.removeById(id);
        return Result.ok();
    }
}

